package com.wjp.conf;

import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatModel;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AIModelConfiguration {

    @Bean
    public ChatMemory chatMemory() {
        return new InMemoryChatMemory(); //使用内存记忆策略
    }

    // 阿里多模态大模型
    @Bean
    public ChatClient chatClient(DashScopeChatModel model, ChatMemory chatMemory, ToolCallbackProvider toolCallbackProvider) {
        return ChatClient
                .builder(model)
                .defaultTools(toolCallbackProvider) //MCP 配置
                .defaultAdvisors(
                        new SimpleLoggerAdvisor(), // 日志打印
                        new MessageChatMemoryAdvisor(chatMemory) //会话记忆
                )
                .build();
    }

    // 阿里千问大模型
    @Bean
    public ChatClient dashScopechatClient(DashScopeChatModel model, ChatMemory chatMemory) {
        return ChatClient
                .builder(model)
                .defaultAdvisors(
                        new SimpleLoggerAdvisor(),
                        new MessageChatMemoryAdvisor(chatMemory)
                )
                .build();
    }

}
